﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HF.Framework;
using HF.BaseWebCtrlLib;
using HF.Business.Common;
using HF.WorkFlow.Const;
using HF.WorkFlow.Engine;
using HF.WorkFlow.DataContract;

public partial class UserControls_AuditMessage : BaseUserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load();
        InitData();
    }
    private void InitData()
    {
        DataTable dt = AuditMessage.GetAuditMsgTableByOper(OperatorInsId);
        if (dt != null && dt.Rows.Count > 0)
        {
            string result = "";
            lbAuditId.Text = dt.Rows[0]["AuditId"].ToString();
            lbWorkflowId.Text = dt.Rows[0]["WorkflowId"].ToString();
            lbWorkflowInsId.Text = dt.Rows[0]["WorkflowInsId"].ToString();
            lbWorktaskId.Text = dt.Rows[0]["WorktaskId"].ToString();
            lbWorktaskInsId.Text = dt.Rows[0]["WorktaskInsId"].ToString();
            lbOperatorInsId.Text = dt.Rows[0]["OperatorInsId"].ToString();
            lbUserId.Text = dt.Rows[0]["AuditUserId"].ToString();
            lbUserName.Text = dt.Rows[0]["AuditUserName"].ToString();
            lbArch.Text = dt.Rows[0]["AuditArch"].ToString();
            lbDuty.Text = dt.Rows[0]["AuditDuty"].ToString();
        
            result = dt.Rows[0]["AuditResult"].ToString();
            if (result == "同意")
            {
                rbtOk.Checked = true;
            }
            else rbtNo.Checked = true;
            lbAuditTime.Text = dt.Rows[0]["AuditTime"].ToString();
            tbxMessage.Text = dt.Rows[0]["Message"].ToString();
            CtrlState = WorkFlowConst.STATE_MOD;
        }
        else
        {
            lbAuditId.Text = Guid.NewGuid().ToString();
            lbWorkflowId.Text =WorkflowId;
            lbWorkflowInsId.Text = WorkflowInsId;
            lbWorktaskId.Text = WorktaskId;
            lbWorktaskInsId.Text = WorktaskInsId;
            lbOperatorInsId.Text = OperatorInsId;
            lbUserId.Text = UserId;
            lbUserName.Text = UserName;
            lbArch.Text =ArchCaption ;
            lbDuty.Text = DutyCaption;
            CtrlState = WorkFlowConst.STATE_ADD;
            lbAuditTime.Text = DateTime.Now.ToShortDateString();
        }
    }
    public override void SaveUserControl(bool IsDraft)
    {
        base.SaveUserControl(IsDraft);


        AuditMessage am = new AuditMessage();
        am.AuditId = lbAuditId.Text;
        am.WorkflowId = lbWorkflowId.Text;
        am.WorkflowInsId = lbWorkflowInsId.Text;
        am.WorktaskId = lbWorktaskId.Text;
        am.WorktaskInsId = lbWorktaskInsId.Text;
        am.OperatorInsId = lbOperatorInsId.Text;
        am.AuditUserId = lbUserId.Text;
        am.AuditUserName = lbUserName.Text;
        am.AuditArch = lbArch.Text;
        am.AuditDuty = lbDuty.Text;
        
        
        if (rbtOk.Checked)
            am.AuditResult = "同意";
        else
            if (rbtNo.Checked)
                am.AuditResult = "拒绝";
        am.Message = tbxMessage.Text;
        if (CtrlState == WorkFlowConst.STATE_ADD)
            am.InsertAuditMessage();
        else
            if (CtrlState == WorkFlowConst.STATE_MOD)
                am.UpdateAuditMessage();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
    
    }
    protected void Button1_Click1(object sender, EventArgs e)
    {
       
    }
}
